package com.david.client.ui.common;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.gwtext.client.core.Ext;

public class RoundCornerBox extends Composite {
	private final VerticalPanel container = new VerticalPanel();

	private String title = "";

	private Div content = null;

	private Element header;

	public RoundCornerBox() {
		initWidget(container);
		container.add(createBox());
	}

	protected Widget createBox() {
		Div rootDiv = new Div();
		Element el = rootDiv.getElement();

		Element parent = el;
		Element tl = DOM.createDiv();
		DOM.setElementProperty(tl, "className", "x-box-tl");

		Element tr = DOM.createDiv();
		DOM.setElementProperty(tr, "className", "x-box-tr");

		Element tc = DOM.createDiv();
		DOM.setElementProperty(tc, "className", "x-box-tc");

		DOM.appendChild(tr, tc);
		DOM.appendChild(tl, tr);
		DOM.appendChild(el, tl);

		Element ml = DOM.createDiv();
		DOM.setElementProperty(ml, "className", "x-box-ml");

		Element mr = DOM.createDiv();
		DOM.setElementProperty(mr, "className", "x-box-mr");

		Element mc = DOM.createDiv();
		DOM.setElementProperty(mc, "className", "x-box-mc");

		DOM.appendChild(mr, mc);
		DOM.appendChild(ml, mr);
		DOM.appendChild(el, ml);

		parent = mc;

		header = DOM.createElement("h3");
		DOM.setStyleAttribute(header, "margin-bottom", "5px");
		DOM.setInnerText(header, title);
		DOM.appendChild(parent, header);
		new Widget() {
			{
				setElement(header);
				setStyleName("FormTitle");
			}
		};

		content = new Div();

		DOM.setElementProperty(content.getElement(), "id", "Content");

		// DOM.setStyleAttribute(content.getElement(), "height",(height-20) +
		// "px" );

		DOM.appendChild(parent, content.getElement());

		Element bl = DOM.createDiv();
		DOM.setElementProperty(bl, "className", "x-box-bl");

		Element br = DOM.createDiv();
		DOM.setElementProperty(br, "className", "x-box-br");

		Element bc = DOM.createDiv();
		DOM.setElementProperty(bc, "className", "x-box-bc");

		DOM.appendChild(br, bc);
		DOM.appendChild(bl, br);
		DOM.appendChild(el, bl);

		return rootDiv;
	}

	public void setContent(Widget w) {
		DOM.appendChild(content.getElement(), w.getElement());
	}

	public void setTitle(String title) {
		this.title = title;
		DOM.setInnerText(header, title);
	}
}
